/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bingo.cartones;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import Bingo.megabingo.MegaBingo;
import Bingo.system.Exc;
import Bingo.system.Persistencia;

/**
 *
 * @author gilberto
 */
public class Find {

    private Persistencia persistencia = new Persistencia();
    private String sql = "";
    private ResultSet rsts = null;
    private Map<String, Integer> map = new HashMap<>();

    //Lista todos los cartones para cargar el array de todos los cartones.
    public List<Beans> listarTodos(String sql) throws Exc, SQLException, Exception {
        List<Beans> listBean = new ArrayList<>();
        rsts = persistencia.executeRsts(sql);
        while (rsts.next()) {
            Beans beans = new Beans(
                    rsts.getInt("id_carton"),
                    rsts.getInt("detalle"),
                    rsts.getInt("suma"));
            listBean.add(beans);
        }
        persistencia.dbDisconnect();
        return listBean;
    }

    public List<Beans> listarJugados(String sql) throws Exc, SQLException, Exception {
        List<Beans> listBean = new ArrayList<>();
        rsts = persistencia.executeRsts(sql);
        while (rsts.next()) {
            Beans beans = new Beans(
                    rsts.getInt("detalle"));
            listBean.add(beans);
        }
        persistencia.dbDisconnect();
        return listBean;
    }

    //Calcula el inicio y fin de cada balotas
    public Map<String, Integer> inicio_fin(Integer modo_juego, String tabla) throws Exc, SQLException, Exception {
        sql = "SELECT detalle + 1 AS inicio FROM " + tabla + " WHERE id = 1";
        rsts = persistencia.executeRsts(sql);
        while (rsts.next()) {
            map.put("inicio", rsts.getInt("inicio"));
        }
        rsts.close();
        sql = "SELECT detalle AS fin FROM " + tabla + " WHERE id = 6";
        rsts = persistencia.executeRsts(sql);
        while (rsts.next()) {
            map.put("fin", rsts.getInt("fin"));
        }
        rsts.close();

        return map;

    }
}
